#!/bin/sh

#
# Test that metadata can be retreived from a file when only part
# of the file is available. This lets apps show metadata in a file
# before it has been completely downloaded.
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"
create_15M_file

EXPECTED_OUTPUT=$WORK/expected_output
ACTUAL_OUTPUT=$WORK/actual_output

cat >$CONFIG <<EOF
meta-product = "product name"
meta-description = "product description"
meta-version = "some version"
meta-platform = "a platform"
meta-architecture = "an architecture"
meta-author = "someone"

file-resource bigfile {
	host-path = "${TESTFILE_15M}"
}
EOF

cat >$EXPECTED_OUTPUT <<EOF
meta-product="product name"
meta-description="product description"
meta-version="some version"
meta-author="someone"
meta-platform="a platform"
meta-architecture="an architecture"
meta-creation-date="2018-05-05T18:10:16Z"
meta-uuid="62a285ff-25b5-5c14-ea5f-0f5286b0e198"
EOF

SOURCE_DATE_EPOCH=1525543816 $FWUP_CREATE -c -f $CONFIG -o $FWFILE

# Only keep the first 512 bytes of the whole 15MB .fw file!
dd if=$FWFILE of=$FWFILE.truncated bs=1 count=512 2>/dev/null

$FWUP_APPLY_NO_CHECK -i $FWFILE.truncated -m > $ACTUAL_OUTPUT

diff -w $EXPECTED_OUTPUT $ACTUAL_OUTPUT
